package com.dayu.web.controller.basic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.basic.domain.BasicStore;
import com.dayu.basic.service.IBasicStoreService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 门店管理Controller
 * 
 * @author HK
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/basic/store")
public class BasicStoreController extends BaseController
{
    @Autowired
    private IBasicStoreService basicStoreService;

    /**
     * 查询门店管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicStore basicStore)
    {
        startPage();
        List<BasicStore> list = basicStoreService.selectBasicStoreList(basicStore);
        return getDataTable(list);
    }

    /**
     * 导出门店管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:store:export')")
    @Log(title = "门店管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasicStore basicStore)
    {
        List<BasicStore> list = basicStoreService.selectBasicStoreList(basicStore);
        ExcelUtil<BasicStore> util = new ExcelUtil<BasicStore>(BasicStore.class);
        return util.exportExcel(list, "store");
    }

    /**
     * 获取门店管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:store:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return AjaxResult.success(basicStoreService.selectBasicStoreById(storeId));
    }

    /**
     * 新增门店管理
     */
    @PreAuthorize("@ss.hasPermi('basic:store:add')")
    @Log(title = "门店管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicStore basicStore)
    {
        return toAjax(basicStoreService.insertBasicStore(basicStore));
    }

    /**
     * 修改门店管理
     */
    @PreAuthorize("@ss.hasPermi('basic:store:edit')")
    @Log(title = "门店管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicStore basicStore)
    {
        return toAjax(basicStoreService.updateBasicStore(basicStore));
    }

    /**
     * 删除门店管理
     */
    @PreAuthorize("@ss.hasPermi('basic:store:remove')")
    @Log(title = "门店管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(basicStoreService.deleteBasicStoreByIds(storeIds));
    }
}
